package com.lagou.task1;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

//自定义实现WritableComparable接口 用语排序用
public class Task1BaseSort implements WritableComparable<Task1BaseSort> {
    private Long num;

    public Task1BaseSort() {
    }

    public Task1BaseSort(Long num) {
        this.num = num;
    }

    public Long getNum() {
        return num;
    }

    public void setNum(Long num) {
        this.num = num;
    }


    @Override
    public String toString() {
        return num.toString() ;
    }

    //比较和排序重写方法
    @Override
    public int compareTo(Task1BaseSort o) {
        //升序
        return num.compareTo(o.getNum());
    }

    //序列化方法:就是把内容输出到网络或者文本中
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(num);
    }

    //反序列化方法
    @Override
    public void readFields(DataInput in) throws IOException {
        this.num = in.readLong();
    }


}
